package pl.skubicha.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import pl.skubicha.domain.Subjects;

public interface SubjectRepository extends JpaRepository< Subjects, Integer > {

	public final static String FIND_BY_SEARCHSTRING_QUERY = "SELECT s FROM Subjects s "
			+ "WHERE s.subjectName "
			+ "like :searchString or s.users.firstName "
			+ "like :searchString or s.users.lastName like :searchString";
	public final static String FIND_ALL_SUBJECTS_FOR_GROUP_QUERY = ""
			+ "SELECT s FROM Subjects s INNER JOIN s.groups g WHERE g.id = :id";

	@Query( FIND_BY_SEARCHSTRING_QUERY )
	public Page< Subjects > findAllMatching( @Param( "searchString" ) String searchString, Pageable page );

	@Query( FIND_ALL_SUBJECTS_FOR_GROUP_QUERY )
	public List< Subjects > findAllSubjectsForGroup( @Param( "id" ) Integer id );
}
